<?php
    //include "../../../config.php";

    Header("content-type: application/x-javascript");

// This code is a sample provided on Yahoo
//  http://developer.yahoo.com/yui/examples/container/panelresize/1.html
//  The code is released under the same licence as the YUI library.
?>

YAHOO.namespace("example.container");

// BEGIN RESIZEPANEL SUBCLASS //
YAHOO.widget.ResizePanel = function(el, userConfig) {
    if (arguments.length > 0) {
        YAHOO.widget.ResizePanel.superclass.constructor.call(this, el, userConfig);
    }
}

YAHOO.extend(YAHOO.widget.ResizePanel, YAHOO.widget.Panel);
YAHOO.widget.ResizePanel.CSS_PANEL_RESIZE = "resizepanel";
YAHOO.widget.ResizePanel.CSS_RESIZE_HANDLE = "resizehandle";

YAHOO.widget.ResizePanel.prototype.init = function(el, userConfig) {
    YAHOO.widget.ResizePanel.superclass.init.call(this, el);
    this.beforeInitEvent.fire(YAHOO.widget.ResizePanel);
    YAHOO.util.Dom.addClass(this.innerElement, YAHOO.widget.ResizePanel.CSS_PANEL_RESIZE);
    this.resizeHandle = document.createElement("DIV");
    this.resizeHandle.id = this.id + "_r";
    this.resizeHandle.className = YAHOO.widget.ResizePanel.CSS_RESIZE_HANDLE;
    this.beforeShowEvent.subscribe(function() {
        this.body.style.overflow = "auto";
    }, this, true);

    this.beforeHideEvent.subscribe(function() {
        /*
             Set the CSS "overflow" property to "hidden" before
             hiding the panel to prevent the scrollbars from
             bleeding through on Firefox for OS X.
        */
        this.body.style.overflow = "hidden";
    }, this, true);

    this.beforeRenderEvent.subscribe(function() {
        /*
             Set the CSS "overflow" property to "hidden" by
             default to prevent the scrollbars from bleeding
             through on Firefox for OS X.
        */
        this.body.style.overflow = "hidden";
        if (! this.footer) {
            this.setFooter("");
        }
    }, this, true);

    this.renderEvent.subscribe(function() {
        var me = this;

        me.innerElement.appendChild(me.resizeHandle);
        this.ddResize = new YAHOO.util.DragDrop(this.resizeHandle.id, this.id);
        this.ddResize.setHandleElId(this.resizeHandle.id);
        var headerHeight = me.header.offsetHeight;
        this.ddResize.onMouseDown = function(e) {

            this.startWidth = me.innerElement.offsetWidth;
            this.startHeight = me.innerElement.offsetHeight;

            me.cfg.setProperty("width", this.startWidth + "px");
            me.cfg.setProperty("height", this.startHeight + "px");

            this.startPos = [YAHOO.util.Event.getPageX(e),
                             YAHOO.util.Event.getPageY(e)];

            me.innerElement.style.overflow = "hidden";
            me.body.style.overflow = "auto";
        }

        this.ddResize.onDrag = function(e) {
            var newPos = [YAHOO.util.Event.getPageX(e),
                          YAHOO.util.Event.getPageY(e)];

            var offsetX = newPos[0] - this.startPos[0];
            var offsetY = newPos[1] - this.startPos[1];

            var newWidth = Math.max(this.startWidth + offsetX, 10);
            var newHeight = Math.max(this.startHeight + offsetY, 10);

            me.cfg.setProperty("width", newWidth + "px");
            me.cfg.setProperty("height", newHeight + "px");

            var bodyHeight = (newHeight - 5 - me.footer.offsetHeight - me.header.offsetHeight - 3);
            if (bodyHeight < 0) {
                bodyHeight = 0;
            }

            me.body.style.height =  bodyHeight + "px";

            var innerHeight = me.innerElement.offsetHeight;
            var innerWidth = me.innerElement.offsetWidth;

            if (innerHeight < headerHeight) {
                me.innerElement.style.height = headerHeight + "px";
            }

            if (innerWidth < 20) {
                me.innerElement.style.width = "20px";
            }
        }

    }, this, true);

    if (userConfig) {
        this.cfg.applyConfig(userConfig, true);
    }

    this.initEvent.fire(YAHOO.widget.ResizePanel);
};

YAHOO.widget.ResizePanel.prototype.toString = function() {
    return "ResizePanel " + this.id;
};

// END RESIZEPANEL SUBCLASS //

// Begin custom Panel code by Folio (NDG) //

function folio_PanelHide( ) {
    YAHOO.example.container.panel1.hideProcId = setTimeout(function() {
            YAHOO.example.container.panel1.hide();
            }, '1500');
    folio_ResizePanelHiding = true;
}

function folio_PanelCancelHide( ) {
    clearTimeout(YAHOO.example.container.panel1.hideProcId);
    YAHOO.example.container.panel1.hideProcId=null;
    folio_ResizePanelHiding = false;
}



// Used to control events being triggered, alternates between
//      allowing CancelHide and Hide.
YAHOO.example.container.panel1 = false;
var folio_ResizePanelHiding = false;
var folio_ResizePanelid = 0;
var folio_ResizePanelEventsDefined = false;

function folio_ShowPanel( id, title, url ) {

    //if(YAHOO.example.container.panel1  == false ) {
    //    YAHOO.example.container.panel1 = new YAHOO.widget.ResizePanel("folio_ResizePanelPanel",
    //        { width:"300px", visible:true, constraintoviewport:true } );

    if( folio_ResizePanelid != id && folio_ResizePanelid != 0 ) {
        // Previously loaded node different from this one.

        // If it is in the process of hiding, cancel event.
        if( folio_ResizePanelHiding ) {
            folio_PanelCancelHide( null, YAHOO.example.container.panel1 );
        }

        // Destroy it
        folio_ResizePanelHiding = false;

        folio_ResizePanelid = 0;
        YAHOO.example.container.panel1.destroy();

        // Continue on to create new node.

    } else if( folio_ResizePanelid == id ) {
        // Previously loaded node same as this one.

        // If it is in the process of hiding, cancel event.
        if( folio_ResizePanelHiding ) {
            folio_PanelCancelHide( null, YAHOO.example.container.panel1 );
        }

        // Make visible.
        if( !YAHOO.example.container.panel1.visible ) {
            YAHOO.example.container.panel1.show();
        }

        // Done, no need to setup new node.
        return true;
    }

    // Set loaded node.
    folio_ResizePanelid = id;

    // Create new panel
    YAHOO.example.container.panel1 =
        new YAHOO.widget.ResizePanel("folio_ResizePanelPanel",
            { width:"300px", visible:true, constraintoviewport:true } );

    // Set information.
    YAHOO.example.container.panel1.setHeader(title);
    YAHOO.example.container.panel1.setBody(
        "<iframe id='folio_ResizePanelpageiframe' " +
        "src='" + url + "=" + id + "'" +
        "width='97%' height='95%'></iframe>");

    // Render next to the link.
    YAHOO.example.container.panel1.render('folio_ResizePanel' + id + 'popup');

    YAHOO.util.Event.addListener("folio_ResizePanelPanel", "mouseover",
        folio_PanelCancelHide);
    YAHOO.util.Event.addListener("folio_ResizePanelPanel", "mouseout",
        folio_PanelHide);

}
